package ru.spb.osll.myfit.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import ru.spb.osll.myfit.common.ProgressCounts;

import com.google.gwt.user.client.rpc.IsSerializable;

public class PageExecutingResult implements Serializable, IsSerializable{

  private static final long serialVersionUID = 8520255971586538783L;

  public enum PageExecutingState {
    PROGRESS, FINISH, NOT_STARTED, FAIL;
  }

  private String m_id;
  ArrayList<Table> executedTables = new ArrayList<Table>();
  private PageExecutingState m_state;
  private ProgressCounts m_counts;

  public PageExecutingResult() {
	  this("-1");
  }
  
  public PageExecutingResult(String id) {
    m_id = id;
    m_counts = new ProgressCounts();
    m_state = PageExecutingState.NOT_STARTED;
  }
  
  public PageExecutingResult(PageExecutingResult mPageResult) {
    m_id = mPageResult.getID();
    m_state = mPageResult.getState();
    executedTables.addAll(mPageResult.getExecutedTables());
    m_counts = mPageResult.getCounts();
  }

  public void setID(String id){
	  m_id = id;
  }

  public PageExecutingState getState() {
    return m_state;
  }

  public void setState(PageExecutingState newState) {
    m_state = newState;
  }

  public String getID() {
    return m_id;
  }
  
  public void setCounts (ProgressCounts counts) {
    m_counts = counts;
  }
  
  public ProgressCounts getCounts() {
    return m_counts;    
  }
  
  public void addExecutedTable(Table table){
    executedTables.add(table);
  }
  
  public void addAllExecutedTable(List<Table> tables){
    executedTables.addAll(tables);
  }

  public List<Table> getExecutedTables(){
    return Collections.unmodifiableList(executedTables);
  }
  
  public void removeAllTables(){
   executedTables.clear(); 
  }
}
